<?php
session_start ();

include 'php/connection.php';

if(isset($_GET['page_name']))
{
	$sql="select page_content from content where page_name='$_GET[page_name]'";
	if(!($result11 = mysql_query($sql)))
	{
		echo mysql_error();
	}
	
}
if(isset($_POST['page_content']))
{
$page_name = $_POST['page_name'];
$sql = "update content set page_content='$_POST[page_content]' where page_name='$_POST[page_name]'";
if(!mysql_query($sql))
	{
		echo mysql_error();
	}
	else
	{
	    ob_start();
		header("Location:content.php?Insert=true");
	}
}
else {
 include_once 'header.php';
$sql1 = "Select id,page_name from content";
 $rs = mysql_query($sql1);
	?>
	
	<table align="left">
	<tr>
	<td>
		Select Page
	</td>
	<td>
	<form name="form1" method="get" action="content.php">
	<select name="page_name" onchange="submit();">
	
	
	<option value="Home">--select--</option>
	<?
	while($row = mysql_fetch_array($rs))
	
	{?>
	<option value="<?=$row['page_name'] ?>" <? if(isset($_GET['page_name'])) {if($row['page_name'] == $_GET['page_name']){echo " selected";}} ?>><?=$row['page_name'] ?></option>
	<? }?>
	
	</select>
	</form>
	</td>
	</tr>
	<?if(isset($_GET['page_name']))
	
	{
	$row=mysql_fetch_assoc($result11)?>
		<tr>
	<td valign="top">
	
	Content:
	</td>
	<td>
	<form name="form2" method="post" action="content.php">
	<input type="hidden" name="page_name" value="<?=$_GET['page_name']?>" />
       <textarea id="elm1" name="page_content" rows="15" cols="80" style="width: 80%">
				 <?echo $row['page_content']; ?>
			</textarea><br>
			<input type="submit" name="save" value="Update" />
			<input type="reset" name="reset" value="Reset" />
			</form>
			</td>
			</tr>
	<?}?>
	</table>
<?}?>